<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<title>{$lang.email_config}</title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<include file="common/ace-tag"/>
	</head>

	<style>
		body{
			background-color:#fff;
		}
		.yui_right{
			float: right;
			margin-bottom: 20px;
		}
		.yui_email{
			width: 60%;
			height: 100%;
			margin-top: 20px;
			margin-left: 20%;
		}
	</style>
	<body >
	<div class="well yui_email">
		<div>
			<button class="btn btn-danger yui_right" style="margin-left: 30px;display: <?php if (!in_array(str_replace('/','',$__url).'-test',think\Session::get('button-resource')) && think\Session::get('username')!='admin') { ?>  none <?php } ?>"" id="test">
				<i class="icon-play align-top bigger-125"></i>
				{$lang.test}
			</button>
			<button class="btn btn-primary yui_right" style="display: <?php if (!in_array(str_replace('/','',$__url).'-save',think\Session::get('button-resource')) && think\Session::get('username')!='admin') { ?>  none <?php } ?>"" id="save">
				<i class="icon-plus align-top bigger-125"></i>
				{$lang.save}
			</button>
		</div>
		<div class="widget-main" style="margin-top: 50px">

			<input type="hidden" name="id" value="{$data.id}"/>
			<div>
				<label >{$lang_filed['mail.host']}</label>
				<input type="text" name="host" placeholder="{$lang_filed['mail.host']}" class="form-control" value="{$data.host}"/>
				<br>
			</div>

			<div>
				<label >{$lang_filed['mail.port']}</label>
				<input type="text" name="port" placeholder="{$lang_filed['mail.port']}" class="form-control" value="{$data.port}"/>
				<br>
			</div>

			<div>
				<label >{$lang_filed['mail.username']}</label>
				<input type="text" name="username"  placeholder="{$lang_filed['mail.username']}" class="form-control" value="{$data.username}"/>
				<br>
			</div>

			<div>
				<label >{$lang_filed['mail.password']}</label>
				<input type="text" name="password" placeholder="{$lang_filed['mail.password']}" class="form-control" value="{$data.password}"/>
				<br>
			</div>

			<div>
				<label >{$lang_filed['mail.from']}</label>
				<input type="text" name="from" placeholder="{$lang_filed['mail.from']}" class="form-control" value="{$data.from}"/>
				<br>
			</div>

			<div>
				<label >{$lang_filed['mail.formname']}</label>
				<input type="text" name="formname" placeholder="{$lang_filed['mail.formname']}" class="form-control" value="{$data.formname}"/>
				<br>
			</div>

			<div>
				<label >{$lang_filed.encoding}</label>
				<input type="text" name="encoding" placeholder="{$lang_filed.encoding}" class="form-control" value="{$data.encoding}"/>
				<br>
			</div>

			<div>
				<label >{$lang_filed['mail.smtp_auth']}</label>
				<select class="form-control" name="smtp_auth">
					<eq name="data.smtp_auth" value="1">
						<option value="1" selected>{$lang_filed.on}</option>
						<option value="2">{$lang_filed.off}</option>
						<else/>
						<option value="2" selected>{$lang_filed.off}</option>
						<option value="1">{$lang_filed.on}</option>
					</eq>
				</select>
				<br>
			</div>

			<div>
				<label >{$lang_filed['mail.smtp_secure']}</label>
				<input type="text" name="smtp_secure" placeholder="{$lang_filed['mail.smtp_secure']}" class="form-control" value="{$data.smtp_secure}"/>
				<br>
			</div>

			<div>
				<label >{$lang.test_email}</label>
				<input type="text" name="test_email" placeholder="{$lang.test_email}" class="form-control" value=""/>
				<br>
			</div>

		</div>
	</div>

	</body>

	<script>
		$(function () {
            //修改
            $("#save").on('click' , function(){
                let id=$("input[name='id']").val();
                let host=$("input[name='host']").val();
                let port=$("input[name='port']").val();
                let username=$("input[name='username']").val();
                let password=$("input[name='password']").val();
                let from=$("input[name='from']").val();
                let formname=$("input[name='formname']").val();
                let smtp_auth=$("select[name='smtp_auth']").val();
                let smtp_secure=$("input[name='smtp_secure']").val();
                let encoding=$("input[name='encoding']").val();
                let loading = layer.load(1, {
                    shade: [0.1,'#fff']
                });
				//ajax提交数据
                $.post("{$__url}",
                    {
                        id:id,
                        host:host,
                        port:port,
                        username:username,
                        password:password,
                        from:from,
                        encoding:encoding,
                        formname:formname,
                        smtp_auth:smtp_auth,
                        smtp_secure:smtp_secure,
                    },
                    function(data,status){
                        if (data['code']==1){
                            layer.open({
                                title: '{$lang.notice}',
                                content: '{$lang.op_success}'
                                ,yes: function(index, layero){
                                    window.location.reload();
                                },cancel: function(){
                                    window.location.reload();
                                }
                            });
                        }else{
                            layer.msg(data['msg']);
                        }
                        layer.close(loading);
                	}, "json"
                );
            });

            //测试
            $("#test").on('click' , function(){
                let host=$("input[name='host']").val();
                let port=$("input[name='port']").val();
                let username=$("input[name='username']").val();
                let password=$("input[name='password']").val();
                let from=$("input[name='from']").val();
                let formname=$("input[name='formname']").val();
                let encoding=$("input[name='encoding']").val();
                let smtp_auth=$("select[name='smtp_auth']").val();
                let smtp_secure=$("input[name='smtp_secure']").val();
                let test_email=$("input[name='test_email']").val();
                if (test_email==''){
                    layer.msg("{$lang.test_email}{$lang.empty}");
                    return;
                }
                let loading = layer.load(1, {
                    shade: [0.1,'#fff']
                });
                //ajax提交数据
                $.post("{$__url}",
                    {
                        host:host,
                        port:port,
                        username:username,
                        password:password,
                        from:from,
                        encoding:encoding,
                        formname:formname,
                        smtp_auth:smtp_auth,
                        smtp_secure:smtp_secure,
						method: 'test',
                        test_email: test_email
                    },
                    function(data,status){
                        if (data['code']==1){
                            layer.open({
                                title: '{$lang.notice}',
                                content: '{$lang.op_success}'
                            });
                        }else{
                            layer.msg(data['msg']);
                        }
                        layer.close(loading);
                    }, "json"
                );
			});

        });
	</script>

</html>
